<template>
  <el-radio-group v-bind="otherProps">
    <el-radio v-for="option in selectOptions" :key="option.value" :label="option.value">{{option.label}}</el-radio>
  </el-radio-group>
</template>

<script setup name="RRadio">

import {ref} from "vue";
import {getDicts} from "@/api/system/dict/data";

const props = defineProps({
  fieldProps: Object
})

const {optionType, options, dict, ...otherProps} = props.fieldProps

const selectOptions = ref()

function getOptions(){
  if(optionType === 'custom'){
    selectOptions.value = options
  }else if(optionType === 'dict'){
    getDicts(dict).then(res => {
      const arr = []
      if(res.data){
        res.data.forEach(dict => {
          arr.push({
            label: dict.dictLabel,
            value: dict.dictValue
          })
        })
        selectOptions.value = arr
      }
    })
  }
}

getOptions()

</script>

<style scoped>

</style>
